"""
表格样式管理模块
"""
from PyQt6.QtWidgets import QTableWidget, QHeaderView

def apply_default_table_style(table: QTableWidget):
    """
    应用默认的表格样式
    :param table: QTableWidget实例
    """
    # 基础样式设置
    table.setShowGrid(False)  # 隐藏网格线
    table.setAlternatingRowColors(True)  # 启用交替行颜色
    
    # 表格样式
    table.setStyleSheet("""
        QTableWidget {
            background-color: white;
            border: none;
            outline: none;
            font-size: 12px;
            alternate-background-color: #fafafa;
        }
        QTableWidget::item {
            padding: 0px 8px;
            border: none;
            border-bottom: 1px solid #ebeef5;
        }
        QHeaderView::section {
            background-color: #f5f7fa;
            padding: 8px;
            border: none;
            border-bottom: 1px solid #ebeef5;
            font-weight: normal;
            color: #909399;
            font-size: 12px;
        }
        QTableWidget::item:selected {
            background-color: transparent;
        }
    """)

def set_columns_stretch(table: QTableWidget):
    """
    设置所有列为自适应宽度
    :param table: QTableWidget实例
    """
    header = table.horizontalHeader()
    for i in range(table.columnCount()):
        header.setSectionResizeMode(i, QHeaderView.ResizeMode.Stretch)
